home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Icon / c / IncDec < prev    next >
Text File  |  1995-07-08  |  5KB  |  133 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Icon.IncDec.c
  12.     Author:  Copyright © 1994 Lee Atkinson, David Leftley
  13.     Version: 1.01 (21 Jun 1995)
  14.     Purpose: High-level icon handling routines: Handler for increment and
  15.              decrement icons
  16.     Mods:    David Leftley - call Icon_SetCaret after each increment/decrement,
  17.                              otherwise the caret is left inbetween digits when
  18.                              99->100 etc.
  19. */
  20.  
  21. #include <stdlib.h>
  22.  
  23. #include "DeskLib:Core.h"
  24. #include "DeskLib:Event.h"
  25. #include "DeskLib:Icon.h"
  26. #include "DeskLib:Window.h"
  27. #include "DeskLib:WimpSWIs.h"
  28.  
  29.  
  30.  
  31.  
  32.  
  33. static void Icon__ResetCaret(const window_handle window, const icon_handle icon)
  34. {
  35.   caret_block caret;
  36.   Wimp_GetCaretPosition(&caret);
  37.   if (caret.window == window && caret.icon == icon)
  38.   { 
  39.     Icon_SetCaret(window,icon);
  40.   }
  41. }
  42.  
  43.  
  44.  
  45. static void Increment(const icon_incdecblock *b)
  46. {
  47.  int i;
  48.  if ((i=Icon_GetInteger(b->window,b->texticon))<(b->max-b->step))
  49.                                Icon_SetInteger(b->window,b->texticon,i+b->step);
  50.       /* if value in text icon is less than the max-step increment it by step */
  51.  else if (i<b->max) Icon_SetInteger(b->window,b->texticon,b->max); /* else if
  52.                                     value less than max, set text icon to max */
  53.  else if (b->loop) Icon_SetInteger(b->window,b->texticon,b->min); /* else if
  54.                                                    loop, set text icon to min */
  55. Icon__ResetCaret(b->window, b->texticon);
  56. }
  57.  
  58.  
  59.  
  60. static void Decrement(const icon_incdecblock *b)
  61. {
  62.  int i;
  63.  if ((i=Icon_GetInteger(b->window,b->texticon))>(b->min+b->step))
  64.                                Icon_SetInteger(b->window,b->texticon,i-b->step);
  65.       /* if value in text icon is more than the min+step decrement it by step */
  66.  else if (i>b->min) Icon_SetInteger(b->window,b->texticon,b->min); /* else if
  67.                                     value more than min, set text icon to min */
  68.  else if (b->loop) Icon_SetInteger(b->window,b->texticon,b->max);/* else if
  69.                                                    loop, set text icon to max */
  70. Icon__ResetCaret(b->window, b->texticon);
  71. }
  72.  
  73.  
  74. static BOOL CheckIncrement(event_pollblock *event,void *ref)
  75. {
  76.  icon_incdecblock *b=(icon_incdecblock *)ref;
  77.  if (event->data.mouse.button.data.select) Increment(b); /* select click */
  78.  else if (event->data.mouse.button.data.adjust) Decrement(b); /* adjust click */
  79.  
  80.  return(FALSE);
  81. }
  82.  
  83.  
  84. static BOOL CheckDecrement(event_pollblock *event,void *ref)
  85. {
  86.  icon_incdecblock *b=(icon_incdecblock *)ref;
  87.  if (event->data.mouse.button.data.select) Decrement(b); /* select click */
  88.  else if (event->data.mouse.button.data.adjust) Increment(b); /* adjust click */
  89.  
  90.  return(FALSE);
  91. }
  92.  
  93. icon_incdecblock *Icon_InitIncDecHandler(const window_handle window,
  94.                                          const icon_handle   texticon,
  95.                                          const icon_handle   incrementicon,
  96.                                          const icon_handle   decrementicon,
  97.                                          const BOOL          loop,
  98.                                          const unsigned int  step,
  99.                                          const int           min,
  100.                                          const int           max,
  101.                                          const int           start)
  102. {
  103.  icon_incdecblock *b;
  104.  b=(icon_incdecblock *)malloc(sizeof(icon_incdecblock));
  105.                                             /* allocate memory for data block */
  106.  if (b==NULL) return NULL;
  107.  b->window       =window;
  108.  b->texticon     =texticon;
  109.  b->incrementicon=incrementicon;
  110.  b->decrementicon=decrementicon;
  111.  b->loop         =loop;
  112.  b->step         =step;
  113.  b->min          =min;
  114.  b->max          =max;
  115.  
  116.  Icon_SetInteger(window,texticon,start);
  117.  if (Event_Claim(event_CLICK,window,incrementicon,CheckIncrement,(void *)b)&&
  118.          Event_Claim(event_CLICK,window,decrementicon,CheckDecrement,(void *)b))
  119.                                                                        return b;
  120.  else return NULL;
  121. }
  122.  
  123. BOOL Icon_ReleaseIncDecHandler(icon_incdecblock *incdecblock)
  124. {
  125.  BOOL result;
  126.  result=(Event_Release(event_CLICK,incdecblock->window,
  127.                 incdecblock->incrementicon,CheckIncrement,(void *)incdecblock)&&
  128.          Event_Release(event_CLICK,incdecblock->window,
  129.                 incdecblock->decrementicon,CheckDecrement,(void *)incdecblock));
  130.  free((void *)incdecblock);
  131.  return result;
  132. }
  133.